// app-user-info.component.ts
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { CommonModule } from '@angular/common';

import { NzAvatarModule } from 'ng-zorro-antd/avatar';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzDropDownModule } from 'ng-zorro-antd/dropdown';
import { NzIconModule } from 'ng-zorro-antd/icon';
@Component({
  selector: 'app-user-info',
  standalone: true,
  imports: [
    CommonModule,
    NzAvatarModule,
    NzButtonModule,
    NzDropDownModule,
    NzIconModule
  ],
  templateUrl: './user-info.component.html',
  styleUrls: ['./user-info.component.less'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppUserInfoComponent {
  @Input() userInfo!: { username: string; role?: string; loginTime?: string | number };
  @Output() logout = new EventEmitter<void>();

  get formattedTime(): string {
    if (!this.userInfo.loginTime) return '';
    const d = new Date(this.userInfo.loginTime);
    return d.toLocaleString('zh-CN', {
      month: '2-digit',
      day: '2-digit',
      hour: '2-digit',
      minute: '2-digit'
    });
  }

  onMenuClick() {
    this.logout.emit();
  }

}
